/**
 * Created by Administrator on 2017/3/14.
 */
var RealName = require('../../src/complex/realName');
var InvestRecord = require('../complex/investRecord');
var AccountMes = require('../complex/accountMes');
var Root = React.createClass({
    getInitialState:function () {
      return {
          investRecord:PageDM.investRecord.value,
          realName:PageDM.realNameInfo.value,
          accountInvest:PageDM.accountInvest.value
      }
    },
    componentDidMount: function(){

        var _this = this;

        UEventHub.on(PageDM.investRecord.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function(v){
            _this.updateInvestRecordHandler(v);
        });
        UEventHub.on(PageDM.accountInvest.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function(v){
            _this.updateAccountInvestHandler(v);
        });
        UEventHub.on(PageDM.realNameInfo.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function(v){
            _this.updateRealNameInfoHandler(v);
        });
        UEventHub.emit("pageLoad","hello world!");
    },
    updateRealNameInfoHandler: function (v) {
        this.setState({
            realName:PageDM.realNameInfo.value
        })
    },
    updateAccountInvestHandler: function (v) {
        this.setState({
            accountInvest:PageDM.accountInvest.value
        })
    },
    updateInvestRecordHandler: function (v) {
        this.setState({
            investRecord:PageDM.investRecord.value
        })

    },
    render: function () {
        var _this = this;
        var PageDM = window.PageDM;
        var investRecordDom = [];

        if(this.state.investRecord.list.length > 0){
            investRecordDom.push(<InvestRecord data={this.state.investRecord.list}/>)
        }else {
            if(this.state.investRecord.noPrecedent == -1){
                investRecordDom.push('')
            }else{
                investRecordDom.push(
                    <div className="nodata">
                        <i className="bg-1"></i>暂无待回收项目
                    </div>
                )
            }

        }
        return (
            <div>

                <div className="mod-account container">
                    <div className="sub-nav" ref="realName">
                        <RealName data={this.state.realName}/>
                    </div>
                    <div className="account my-account">
                        <div className="count" ref="accountInvest">
                            <AccountMes {...this.state.accountInvest}/>
                        </div>
                        <div className="investment-record">
                            <div className="title"><b></b>待回收项目<b></b></div>
                                {investRecordDom}

                        </div>
                    </div>
                    <div className="clear"></div>
                </div>
                <div className="pagination account"  ref="pagination"></div>

            </div>
        )
    }
});
ReactDOM.render(<Root/>, document.getElementById('giraffe'));